package day6;

public class Company {
    String name;
    String adress;
    String telephone;
    String scope;
    Staff[] a = new Staff[500];
    int count = 0;

    public void add(Staff b) {
        if (count == a.length) {
            System.out.println("员工已招满");
        } else {
            a[count]=new Staff();
            a[count].name = b.name;
            a[count].age = b.age;
            a[count].sex = b.sex;
            a[count].job = b.job;
            a[count].salary = b.salary;
            count++;
        }
    }
    public boolean  checkStaffNoRepeat(String stname){
        a[count]=new Staff();
        for(int i=0;i<count;i++){
            if(a[i].name.equals(stname)){
                System.out.println("员工信息已存在，请重新录入");
                return true;
            }
        }
        return false;
    }

    public void showinfo() {
        for (int i = 0; i < count; i++) {
            System.out.println("姓名：" + a[i].name + "；性别：" + a[i].sex + "；年龄：" + a[i].age + ";职位：" + a[i].job + ";薪水：" + a[i].salary);
        }
    }

    public boolean dismiss(String disname) {
       // int index = 0;
        for (int i = 0; i < count; i++) {
            if (a[i].name.equals(disname)) {
                System.out.println(disname + "已被辞退");
                for(int j=i;j<count-1;j++) {
                    a[j] = a[j + 1];
                }
                a[count-1]=null;
                count--;
                return true;
            }
        }

        return true;
    }
    public void findTopSalary(){
        double max=0;
        for(int i=0;i<count;i++){
            if(a[i].salary>max){
                max=a[i].salary;
            }
        }
        for(int index=0;index<count;index++){
            if(a[index].salary==max){
                System.out.println("姓名：" + a[index].name + "；性别：" + a[index].sex + "；年龄：" + a[index].age + ";职位：" + a[index].job + ";薪水：" + a[index].salary);
            }
        }

    }
    public void sortBySalDesc(){
        Staff max;
        for(int i=0;i<count-1;i++){
            for(int j=i;j<count-1;j++)
            if(a[i].salary<a[j+1].salary){
                max=a[i];
                a[i]=a[j+1];
                a[j+1]=max;
            }
        }
        this.showinfo();
    }
    public double getavg(){
        double sum=0,avg;
        for(int i=0;i<count;i++){
            sum+=a[i].salary;
        }
        avg=sum/count;
        System.out.println("员工的平均工资为"+avg);
        return avg;
    }
    public boolean incSalary(){
        for(int i=0;i<count;i++){
            if (a[i].salary<5000){
                a[i].salary+=500;
                return true;
            }
            a[i].salary+=100;
        }
        this.showinfo();
        return true;
    }
}

